home *** CD-ROM | disk | FTP | other *** search
| Text File | 1996-03-11 | 3.8 KB | 133 lines | [TEXT/CWIE] |
- // functions used by the modal dialog displaying a picture.
- /* this series of functions opens and closes a pre-made file. In order to understand how
- this code works, you should also review the code in picture creator.c, as that code
- creates the file that is manipulated here */
-
- #include "BTreeDef.h"
- #include "BTreeProtos.h"
- #include "StandardFile.h"
-
- // some macros
- #define kPicBlockSize 100L
- #define kPicSpareBlocks 10L
- #define kPicType 'IExP'
- #define kPicCreator 'IExA'
-
- // used to store size and data for picture and text
- struct DataInfoType {
- long PicSize;
- long PicAddr;
- long StrSize;
- long StrAddr;
- };
- typedef struct DataInfoType DataInfoType;
-
-
- // These are variables that will be used by B-Tree Helper
- // Note that BTH allows multiple open files, but each file must
- //have its own file control handle
- TreeListHandle gPictureTrees;
- FileControlHandle gPictureFCH;
- long gPicBlockSize;
- long gPicSpareBlocks;
- StandardFileReply gPicFileReply;
- SFTypeList gPicTypeList;
- short gPicNumTypes;
- short gPicPermission;
- short PicError;
- long DataSize;
- FileAddr DataAddr;
- DataInfoType DataInfo;
- FileAddr DataInfoAddr;
- DialogPtr gPictureDialog;
- Boolean fileIsOpen;
-
- // prototypes
- void HandlePictureDialog(void);
- void OpenPictureFile(void);
- void ClosePictureFile(void);
-
-
- // if you don't understand this function, you shouldn't be reading this...
- void HandlePictureDialog(void){
- short theItem;
- Boolean theEnd = FALSE;
- fileIsOpen = FALSE;
- gPictureDialog = GetNewDialog(260,NULL,(WindowPtr)-1);
- do{
- ModalDialog(NULL,&theItem);
- switch (theItem) {
- case 1:
- OpenPictureFile();
- break;
- case 2:
- if (fileIsOpen)
- ClosePictureFile();
- // need to reset the picture in the item list
- // otherwise mac toolbox gets confused.
- // don't ask me why.
- ReleaseResource(GetResource('PICT', 128));
- theEnd = TRUE;
- break;
- }//switch
- }//do statement
- while (!theEnd);
- DisposeDialog(gPictureDialog);
- }
-
- // close the picture file
- void ClosePictureFile(void) {
- short theErr = Close_BTreeFile(&gPictureFCH);
- fileIsOpen = FALSE;
- }//function
-
- // open the picture file
- void OpenPictureFile(void) {
- short OpenFileErr = noErr;
- short itemNo;
- short itemType;
- Handle item;
- Str255 theString;
- Rect box;
- // set up for standard file call
- gPicTypeList[0]= kPicType;
- StandardGetFile(NULL, 1, gPicTypeList, &gPicFileReply);
- if (!gPicFileReply.sfGood){
- //return if user cancels
- OpenFileErr = userCanceledErr;
- return;
- }
- //pass the gFileReply to our B-Tree routine
- OpenFileErr = FSpOpen_BTreeFile(&gPicFileReply,fsCurPerm,&gPictureFCH);
- if (OpenFileErr != noErr)
- return;
- // read in the data in three steps. First read in the little struct that has
- // the information about the other pieces of data. Its address was tucked away
- // in the .application1 field of the file control record when we made this file
- OpenFileErr = Read_Data(gPictureFCH,16,(**gPictureFCH).application1,(Ptr)&DataInfo);
- fileIsOpen = TRUE;
- //read in the picture data first
- itemNo = 3; //picture item
- // retrieve the Picture item handle
- GetDialogItem(gPictureDialog, itemNo, &itemType, &item, &box);
- // set handle size to the size of the pict in the file
- SetHandleSize(item,DataInfo.PicSize);
- HLock(item);
- // read in the picture
- OpenFileErr = Read_Data(gPictureFCH,DataInfo.PicSize,DataInfo.PicAddr,*item);
- HUnlock(item);
- //update the dialog item list
- SetDialogItem(gPictureDialog,itemNo, itemType, item, &box);
- // now do the same for the text, in the exact same way
- itemNo = 4;
- GetDialogItem(gPictureDialog, itemNo, &itemType, &item, &box);
- OpenFileErr = Read_Data(gPictureFCH, DataInfo.StrSize, DataInfo.StrAddr, (Ptr)(theString+1));
- theString[0] = DataInfo.StrSize;
- SetDialogItemText(item,theString);
- SetDialogItem(gPictureDialog,itemNo,itemType,item,&box);
- // update the dialog display
- DrawDialog(gPictureDialog);
-
-
- }//function
-